#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <ctime>

#include "kahansum.h"
#include "median.h"
#include "Vector.h"
#include "utils.h"
#include "MLP.h"
using namespace std;

int main3()
{
	vector<DMVector> vlist;
	vector<int> vp;
	//KMeans kmean(4);
	int i, j;
	srand( (unsigned)time( NULL ) );

	string filename = "dataset-4";
	string outfile = "out-4-19";
	int hd = 16;
	int num = 1024;
	double lrate = 0.015;
	/*cout << "input: inputfile, learning rate, hidden plane, outputfile" << endl;
	cin >> filename;
	cin >> lrate;
	cin >> hd;
	cin >> outfile;*/

	cout << "input: hiddenlayer, loopNum, learningRate,inputfile,outputfile" << endl;

	while ( cin >> hd >> num >> lrate >> filename >> outfile )
	{
		vlist = read_data ( filename, vp );

		MLP mlp(vlist[0].size(), hd, lrate);
		int max, size, index;
		size = vlist.size();
		max = (int)(vlist.size() * 0.8);
		i = 0;
		mlp.reset();
		
		vector<double> vmean = vector_mean ( vlist );
		int sj = vlist[0].size();
		for ( i = 0; i < size; ++i )
		{
			for ( j = 0; j < sj; ++j )
			{
				vlist[i].set ( j, vlist[i].get ( j ) - vmean[j] );
			}
			/*double nor = vlist[i].norm();
			for ( j = 0; j < sj; ++j )
			{
				vlist[i].set ( j, vlist[i].get ( j ) / nor );
			}*/
		}

		i = 0;
		while ( i < num  )
		{
			index = rand() % size;
			mlp.update ( vlist[index], vp[index] == 1 ? true : false );
			i++;
		}

		for ( i = 0; i < size; ++i )
		{
			if ( mlp.classify ( vlist[i] ) == true )
				vp[i] = 1;
			else
				vp[i] = 0;
		}

		write_data ( outfile, vlist, vp );
		cout << "finished" << endl;
	}

	return 0;
}